/*
 * @Authoryour name
 * @Date2021-01-02 18:15:24
 * @LastEditTime2021-01-02 18:15:24
 * @LastEditorsyour name
 * @DescriptionIn User Settings Edit
 * @FilePath\ART-Pi_STM32H750_Bootloader\User\bootloader\boot\boot.c
 */
#include "boot.h"
#include "flash_if.h"
#include "menu.h"

#define APPLICATION_ADDRESS  (uint32_t)0x90000000

static void boot_start_print(void);

pFunction JumpToApplication;
volatile uint32_t JumpAddress = APPLICATION_ADDRESS;

void boot_init(void)
{
    /* Bsp init */
    board_bsp_init();
    /* Print the boot start information */
    boot_start_print();
}

void boot_main(void)
{
    /* Test if Key push-button on STM32L476G-EVAL Board is pressed */
    if (bsp_key_get_status(KEY_IDX_USER) == KEY_STA_PRESSED)
    {
        /* Initialise Flash */
        FLASH_If_Init();
        /* Display main menu */
        Main_Menu();
    }
    /* Keep the user application running */
    else
    {
        /* Deinit the bsp */
        board_bsp_deinit();
        /* Jump to the Application */
        ProgramExecution(APPLICATION_ADDRESS);
    }

    for( ; ; );
}


static void boot_start_print(void)
{
    printf("\r\n======================================================================");
    printf("\r\n=                                                                    =");
    printf("\r\n=   ART-Pi In-Application Programming Application  (Version 1.0.0)   =");
    printf("\r\n=                          By Bowenwangy                             =");
    printf("\r\n=                                                                    =");
    printf("\r\n======================================================================");
    printf("\r\n\r\n");
}
